import router from "./router";
import store from "@/store"
// const blackList = ["Login"]
router.beforeEach((to, from, next) => {
  const token = Cookies.get("token");
  if (to.path === "/login") {
    if (token) {
      next("/")
    } else {
      next()
    }
  } else {
    if (token) {
      next()
    } else {
      next("/login")
    }
  }
});
router.afterEach((transition) => {
})
//  路由跳转失败解决
router.onError((error) => {
  const pattern = /Loading chunk (\d)+ failed/g;
  const isChunkLoadFailed = error.message.match(pattern);
  const targetPath = router.history.pending.fullPath;
  if (isChunkLoadFailed) {
    router.replace(targetPath);
  }
})
